home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / tests / etc / etc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-06-17  |  1.7 KB  |  77 lines

  1. /* 
  2.  * etc.c --
  3.  *
  4.  *    This file contains a program that exercises the etc
  5.  *    library facilities.  Invoke it with no parameters;  it
  6.  *    will print messages on stderr for any problems it detects
  7.  *    with the string procedures.
  8.  *
  9.  * Copyright 1988 Regents of the University of California
  10.  * Permission to use, copy, modify, and distribute this
  11.  * software and its documentation for any purpose and without
  12.  * fee is hereby granted, provided that the above copyright
  13.  * notice appear in all copies.  The University of California
  14.  * makes no representations about the suitability of this
  15.  * software for any purpose.  It is provided "as is" without
  16.  * express or implied warranty.
  17.  */
  18.  
  19. #ifndef lint
  20. static char rcsid[] = "$Header: etc.c,v 1.1 88/04/28 10:15:38 ouster Exp $ SPRITE (Berkeley)";
  21. #endif not lint
  22.  
  23. #include <stdio.h>
  24. #include <varargs.h>
  25.  
  26. #define error(string) \
  27.     fprintf(stderr, string); \
  28.     exit(1);
  29.  
  30. void
  31. varCheck(numArgs, va_alist)
  32.     int numArgs;        /* Number of arguments in addition to this
  33.                  * one.  Must alternate int and double,
  34.                  * in ascending integer order. */
  35.     va_dcl
  36. {
  37.     va_list args;
  38.     int i;
  39.     double d, checkD = 1.0;
  40.     int val, checkVal = 1;
  41.  
  42.     va_start(args);
  43.     for (i = 1; i <= numArgs; i++) {
  44.     if (i & 1) {
  45.         val = va_arg(args, int);
  46.         if (val != checkVal) {
  47.         fprintf(stderr, "varargs error 1, arg %d\n", i);
  48.         exit(1);
  49.         }
  50.         checkVal += 1;
  51.     } else {
  52.         d = va_arg(args, double);
  53.         if (d != checkD) {
  54.         fprintf(stderr, "varargs error 2, arg %d\n", i);
  55.         exit(1);
  56.         }
  57.         checkD += 1.0;
  58.     }
  59.     }
  60.     va_end(args);
  61. }
  62.  
  63. main()
  64. {
  65.     int result = 0;
  66.  
  67.     /*
  68.      * varargs
  69.      */
  70.  
  71.     varCheck(1, 1);
  72.     varCheck(5, 1, 1.0, 2, 2.0, 3);
  73.     varCheck(10, 1, 1.0, 2, 2.0, 3, 3.0, 4, 4.0, 5, 5.0);
  74.  
  75.     return result;
  76. }
  77.